// pages/index/my/my.js
var httpUtil = require('../../../utils/httpUtil.js')
var uiUtil = require('../../../utils/uiUtil.js')
var util = require('../../../utils/util.js')
var app = getApp()
var that

Page({
  /**
   * 页面的初始数据
   */
  data: {
    identity: null,
    data: null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    that = this
    uiUtil.showLoading("正在加载中..")
    that.getMyServicesRequest()
    that.setData({
      identity: app.globalData.identity
    })
  },
  onShareAppMessage: function(res) {
    return util.handleShareApp()
  },

  /**
   * 专属客服点击
   */
  onContactClick() {
    var hotlineNo = this.data.data.hotlineNo
    if (hotlineNo) {
      wx.makePhoneCall({
        phoneNumber: hotlineNo,
      })
    }
  },

  /**
   * 立即续费
   */
  onRenewClick() {
    // uiUtil.showToast("续费请联系您的专属管家")
    wx.navigateTo({
      url: '../../order/renew-temp/renew-temp',
    })
  },
  onMyServiceClick(e) {
    var href = e.currentTarget.dataset.href
    util.handleHref(href)
  },

  /**
   * 获取个人信息、权益信息
   */
  getMyServicesRequest() {
    httpUtil.PostRequest("my_services", {}, {
      success(res) {
        that.setData({
          data: res
        })
      },
      fail(code, res) {},
      complete() {
        uiUtil.hideLoading()
      }
    })
  },

  /**
   * 我的特权点击
   */
  onSpecialItemClick(e) {
    var index = e.currentTarget.dataset.index
    var item = that.data.data.specialList[index]
    var url = encodeURIComponent(item.href)
    var title = encodeURIComponent(item.name)
    wx.navigateTo({
      url: '/pages/web/web?url=' + url + '&title=' + title
    })
  },
  /**
   * 关于按钮点击
   */
  onAboutClick(e){
    var url = "https://files.fengchanhui.wizhong.com/res/page/about/index.html"
    wx.navigateTo({
      url: '/pages/web/web?url=' +decodeURIComponent(url)
    })
  }

})